package cn.dapeng.sort;

import cn.dapeng.utils.BuilderArray;

import java.util.HashSet;
import java.util.Set;

/**
 * @BelongProject study
 * @BelongPackage cn.dapeng.sort
 * @Description TODO
 * @ClassName LambdaTest
 * @Author xupenghong
 * @Date 2024/8/22 11:27
 * @Version 1.0.0
 */
public class LambdaTest {

    /**
     * 初始化一个数组，把大于50的数收集到Set集合中
     *
     * @param args
     */
    public static void main(String[] args) {
        int[] array = BuilderArray.builderArray(100, 50);

        Set<Integer> numberSet = new HashSet<>();
        boolean r = isGetterThanNumber(array, 50, n -> {
            numberSet.add(n);
            return true;
        });

        System.out.println(r);
        System.out.println(numberSet);
    }

    public static boolean isGetterThanNumber(int[] array, int getterThanNum, Callback callback) {
        boolean r = false;
        for (int n : array) {
            if (n > getterThanNum) {
                r = true;
                if (!callback.collect(n)) {
                    return r;
                }
            }
        }
        return r;
    }


    @FunctionalInterface
    public interface Callback {

        boolean collect(int num);
    }
}
